import React, { Component } from 'react'

export default class Footer extends Component {
    handleCheckAll = (event) => {
        const { checkAllTodo } = this.props
        checkAllTodo(event.target.checked)
    }
    handleClearDone = () => {
        const { delDoneTodo } = this.props
        delDoneTodo()
    }
    render() {
        const { todos } = this.props
        const total = todos.length
        const doneTotal = todos.reduce((pre, todo) => {
            return pre + (todo.done ? 1 : 0)
        }, 0)
        return (
            <div>
                <div className="todo-footer">
                    <label>
                        <input type="checkbox" checked={doneTotal === total && total !== 0 ? true : false} onChange={this.handleCheckAll} />
                    </label>
                    <span>
                        <span>已完成{doneTotal}</span> / 全部{total}
                    </span>
                    <button className="btn btn-danger" onClick={this.handleClearDone} >清除已完成任务</button>
                </div>
            </div>
        )
    }
}
